package com.bdqn.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

//读取配置文件的工具类----单例类
public class Single {
    private static Single single;
    private static Properties properties;
    //私有构造方法，项目运行期间，只执行一次
    private Single(){
        String configFile = "database.properties";
        properties=new Properties();
        //得到当前类的类加载器并将配置文件加载到输入流中
        InputStream is=Single.class.getClassLoader().getResourceAsStream(configFile);
        try {
            properties.load(is);
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //定义一个静态内部类，是将对象的创建工作交给静态内部类
    public static class SingleHelper{
       private static final Single INSTANCE=new Single();
    }
    //全局访问点
    public static Single getInstance(){
        single=SingleHelper.INSTANCE;
        return single;
    }
    public String getValue(String key){

        return properties.getProperty(key);
    }
    public static Single test(){
        return single;
    }
}
